﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MockupDesigner.Items.Grid
{
    public class DataGridHelper
    {
        public const string VAL_TRUE = "[x]";
        public const string VAL_FALSE = "[]";
        public const string EMPTY_CELL = "[EMPTY]";

        public static Type GetColumnType(string[] colItems)
        {
            for (int i = 1; i < colItems.Count(); i++)
            {
                if (colItems[i] != VAL_TRUE && colItems[i] != VAL_FALSE)
                {
                    return typeof(string);
                }
            }
            return typeof(bool);
        }

        public static object GetRealCellVal(string cellVal, Type dataType)
        {
            switch (dataType.Name.ToLower())
            {
                case "string":
                    if(cellVal == EMPTY_CELL)
                        return string.Empty;
                    else
                    {
                    return cellVal;
                    }
                case "boolean":
                    return cellVal == VAL_TRUE ? true : false;
            }
            throw new NotSupportedException(string.Concat("Type not supported: ", dataType.Name));
        }

    }
}
